/*
 * TableroM2.java
 *
 * Created on 2 de junio de 2009, 04:36 AM
 */
package gui;

import Multimedia.MediaSonido;
import conexion.SocketListener;
import conexion.SocketServer;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.ImageIcon;
import javax.swing.JOptionPane;
import mundo.Baraja;
import mundo.Carta;

/**
 *
 * @author  Arquitectura
 */
public class TableroM2 extends javax.swing.JFrame implements SocketListener {

    private SocketServer socket;
    private ArrayList<Carta> todas;
    private ArrayList<Carta> anfitrion;
    private ArrayList<Carta> jugador1;
    private ArrayList<Carta> jugada;
    private double puntosAlfitrion;
    private double puntosJugador1;
    private int empates;
    private int actual;
    private int actual2;
    private InformeJuego ij;
    private Baraja baraja;
    private boolean adelante;
    private int conCuartetosA;
    private int conCuartetosJ;
    private Home gc;

    /** Creates new form TableroM2 */
    public TableroM2(MediaSonido sonidoLoginEntrada,Home gc) {
        initComponents();

        initComponents();
        xPnlFondo pnlFondo = new xPnlFondo(17);
        this.add(pnlFondo);
        this.pack();
        this.setSize(800, 635); //El 635 depende (alto) depende del Skin usado.
        this.setLocationRelativeTo(null);
        this.gc=gc;

        todas = new ArrayList<Carta>();
        anfitrion = new ArrayList<Carta>();
        jugador1 = new ArrayList<Carta>();
        jugada = new ArrayList<Carta>();
        puntosAlfitrion = 0;
        puntosJugador1 = 0;
        empates = 0;
        baraja = new Baraja();
        actual = 0;
        actual2 = 0;
        adelante = false;
        conCuartetosA = 0;
        conCuartetosJ = 0;
        this.setVisible(true);
        //this.iniciar();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jlJugador = new javax.swing.JLabel();
        jlTurnoActual = new javax.swing.JLabel();
        jPanel1 = new javax.swing.JPanel();
        jlSiguiente = new javax.swing.JLabel();
        jlAnterior = new javax.swing.JLabel();
        CartaMuestra = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        jlp = new javax.swing.JLabel();
        jlPuntos = new javax.swing.JLabel();
        jbRepartir = new javax.swing.JButton();
        jbAbandonar = new javax.swing.JButton();
        jbConsultar = new javax.swing.JButton();
        jbRealizar = new javax.swing.JButton();
        jPanel3 = new javax.swing.JPanel();
        jrBajarse = new javax.swing.JRadioButton();
        jrPedir = new javax.swing.JRadioButton();
        jlNumero = new javax.swing.JLabel();
        jcNumero = new javax.swing.JComboBox();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jlJugador.setText("Jugador1");

        jlTurnoActual.setText("jLabel1");

        jPanel1.setOpaque(false);

        jlSiguiente.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gui/BTN_next.png"))); // NOI18N
        jlSiguiente.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jlSiguienteMouseClicked(evt);
            }
        });

        jlAnterior.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gui/BTN_previous.png"))); // NOI18N
        jlAnterior.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jlAnteriorMouseClicked(evt);
            }
        });

        CartaMuestra.setText("jLabel1");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(45, 45, 45)
                .addComponent(jlAnterior)
                .addGap(97, 97, 97)
                .addComponent(CartaMuestra, javax.swing.GroupLayout.PREFERRED_SIZE, 227, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(81, 81, 81)
                .addComponent(jlSiguiente)
                .addContainerGap(48, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap(21, Short.MAX_VALUE)
                .addComponent(CartaMuestra, javax.swing.GroupLayout.PREFERRED_SIZE, 344, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(122, 122, 122)
                .addComponent(jlAnterior)
                .addContainerGap(126, Short.MAX_VALUE))
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(124, 124, 124)
                .addComponent(jlSiguiente)
                .addContainerGap(124, Short.MAX_VALUE))
        );

        jPanel2.setOpaque(false);

        jlp.setText("Puntos:");

        jbRepartir.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gui/BTN_repartirCartas.png"))); // NOI18N
        jbRepartir.setBorder(null);
        jbRepartir.setBorderPainted(false);
        jbRepartir.setContentAreaFilled(false);
        jbRepartir.setEnabled(false);
        jbRepartir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbRepartirActionPerformed(evt);
            }
        });

        jbAbandonar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gui/BTN_cancelar.png"))); // NOI18N
        jbAbandonar.setBorder(null);
        jbAbandonar.setBorderPainted(false);
        jbAbandonar.setContentAreaFilled(false);
        jbAbandonar.setEnabled(false);
        jbAbandonar.setRolloverIcon(new javax.swing.ImageIcon(getClass().getResource("/gui/BTN_cancelar_roll.png"))); // NOI18N
        jbAbandonar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbAbandonarActionPerformed(evt);
            }
        });

        jbConsultar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gui/BTN_ConsultarInforme.png"))); // NOI18N
        jbConsultar.setBorder(null);
        jbConsultar.setBorderPainted(false);
        jbConsultar.setContentAreaFilled(false);
        jbConsultar.setEnabled(false);
        jbConsultar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbConsultarActionPerformed(evt);
            }
        });

        jbRealizar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gui/BTN_realizarJugada.png"))); // NOI18N
        jbRealizar.setBorder(null);
        jbRealizar.setBorderPainted(false);
        jbRealizar.setContentAreaFilled(false);
        jbRealizar.setEnabled(false);
        jbRealizar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbRealizarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jlp)
                .addGap(4, 4, 4)
                .addComponent(jlPuntos, javax.swing.GroupLayout.PREFERRED_SIZE, 117, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 28, Short.MAX_VALUE)
                .addComponent(jbRepartir)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jbAbandonar)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jbConsultar)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jbRealizar)
                .addGap(14, 14, 14))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jbRepartir)
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jbRealizar)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jbAbandonar)
                            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addComponent(jbConsultar)
                                .addComponent(jlPuntos, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jlp)))))
                .addContainerGap(26, Short.MAX_VALUE))
        );

        jPanel3.setOpaque(false);

        jrBajarse.setText("Bajarse");
        jrBajarse.setBorder(null);
        jrBajarse.setEnabled(false);
        jrBajarse.setOpaque(false);
        jrBajarse.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jrBajarseActionPerformed(evt);
            }
        });

        jrPedir.setText("Pedir Carta");
        jrPedir.setBorder(null);
        jrPedir.setEnabled(false);
        jrPedir.setOpaque(false);
        jrPedir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jrPedirActionPerformed(evt);
            }
        });

        jlNumero.setText("Numero:");

        jcNumero.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "", "1", "2", "3", "4", "5", "6", "7", "8" }));
        jcNumero.setEnabled(false);

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jlNumero)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(jrBajarse)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jrPedir))
                    .addComponent(jcNumero, javax.swing.GroupLayout.Alignment.LEADING, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(10, 10, 10))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jcNumero, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jlNumero))
                        .addGap(41, 41, 41))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jrPedir)
                            .addComponent(jrBajarse))))
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addGap(136, 136, 136)
                        .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(110, 110, 110)
                        .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, 197, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(21, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGap(176, 176, 176)
                .addComponent(jlJugador)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 342, Short.MAX_VALUE)
                .addComponent(jlTurnoActual, javax.swing.GroupLayout.PREFERRED_SIZE, 53, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(176, 176, 176))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(91, 91, 91)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jlTurnoActual)
                    .addComponent(jlJugador, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-800)/2, (screenSize.height-635)/2, 800, 635);
    }// </editor-fold>//GEN-END:initComponents

    private void jbRepartirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbRepartirActionPerformed
        // TODO add your handling code here:
        todas = new ArrayList<Carta>(baraja.repartirCartas());
        for (int i = 0; i < todas.size(); i++) {
            if (todas.get(i).isComodin() == true) {
                todas.remove(i);
            }
        }


        for (int i = 0; i < todas.size(); i++) {
            if (i <= 15) {
                anfitrion.add(todas.get(i));
            } else if ((15 < i) && (i < 32)) {
                jugador1.add(todas.get(i));
            }
            System.out.println(todas.get(i).getNumero() + todas.get(i).getLetra());
        }

        if (baraja.esta1A(anfitrion) == true) {
            JOptionPane.showMessageDialog(null, "Empieza Anfitrion", "TURNO", JOptionPane.INFORMATION_MESSAGE);
            this.jlTurnoActual.setText("ALFITRION");
            this.jcNumero.setEnabled(true);
            this.jrPedir.setEnabled(true);
            this.jrBajarse.setEnabled(true);

            socket.send("3");
            jbRealizar.setEnabled(true);
        } else {
            this.jlTurnoActual.setText("JUGADOR1");
            JOptionPane.showMessageDialog(null, "Empieza Jugador1", "TURNO", JOptionPane.INFORMATION_MESSAGE);
            this.jlTurnoActual.setText("JUGADOR 1");
            socket.send("4");
            jbRealizar.setEnabled(false);
        }
        //this.jtCarta.setText("" + anfitrion.get(0).getNumero() + " " + anfitrion.get(0).getLetra());

        ImageIcon imagenFondoR = new ImageIcon();
        imagenFondoR = new ImageIcon(getClass().getResource(this.anfitrion.get(actual).getURL()));
        this.CartaMuestra.setIcon(imagenFondoR);

        socket.send("5" + jugador1.get(0).getNumero() + jugador1.get(0).getLetra());
        jbAbandonar.setEnabled(true);
        jbConsultar.setEnabled(true);
        this.jbRepartir.setEnabled(false);
    }

    public void iniciar(int puerto) {

        int p = 0;
        p = puerto;
        socket = new SocketServer(p, this);
        socket.send("Hola soy servidor");
        this.jbRepartir.setEnabled(true);
        this.jlPuntos.setText("" + this.puntosAlfitrion);
        System.out.println(puerto);
    }

    public void receiveData(String data) {
        System.out.println(data);

        if (data.equalsIgnoreCase("1")) {//siguiente   

            if (actual2 == (this.jugador1.size() - 1)) {
                actual2 = 0;
                socket.send("6" + jugador1.get(actual2).getNumero() + jugador1.get(actual2).getLetra());

            } else {
                actual2++;
                socket.send("6" + jugador1.get(actual2).getNumero() + jugador1.get(actual2).getLetra());
            }
        } else if (data.equalsIgnoreCase("2"))//anterior
        {
            if (actual2 == 0) {
                actual2 = (this.jugador1.size() - 1);
                socket.send("7" + jugador1.get(actual2).getNumero() + jugador1.get(actual2).getLetra());
            } else {
                actual2--;
                socket.send("7" + jugador1.get(actual2).getNumero() + jugador1.get(actual2).getLetra());
            }
        } else if (data.substring(0, 1).equalsIgnoreCase("3")) {
            JOptionPane.showMessageDialog(null, "El Jugador1 Abandono la partida!", "INFORMACION", JOptionPane.INFORMATION_MESSAGE);
            this.dispose();
            this.gc.setVisible(true);
            try {
                this.ij.dispose();
            } catch (Exception e) {
            }
        } else if ((data.substring(0, 1).equalsIgnoreCase("6"))) {
            JOptionPane.showMessageDialog(null, "EMPATE", "INFORMACION", JOptionPane.INFORMATION_MESSAGE);
            this.dispose();
            this.gc.setVisible(true);

        } else if ((data.substring(0, 1).equalsIgnoreCase("7"))) {
            JOptionPane.showMessageDialog(null, "GANASTE!", "INFORMACION", JOptionPane.INFORMATION_MESSAGE);
            this.dispose();
            this.gc.setVisible(true);
        } else if ((data.substring(0, 1).equalsIgnoreCase("8"))) {
            JOptionPane.showMessageDialog(null, "PERDISTE!", "INFORMACION", JOptionPane.INFORMATION_MESSAGE);
            this.dispose();
            this.gc.setVisible(true);
        } else if (data.substring(0, 1).equalsIgnoreCase("9")) {
            Carta c = this.baraja.jugadaModalidad1(Integer.parseInt(data.substring(1)), this.anfitrion);
            if (c != null) {
                this.jugador1.add(c);
                socket.send("A7");
                this.jbRealizar.setEnabled(false);
                this.jrBajarse.setEnabled(false);
                this.jrPedir.setEnabled(false);
                this.jcNumero.setEnabled(false);


            } else {
                socket.send("A6");
                this.jbRealizar.setEnabled(true);
                this.jrBajarse.setEnabled(true);
                this.jrPedir.setEnabled(true);
                this.jcNumero.setEnabled(true);
            }
        } else if (data.substring(0, 2).equalsIgnoreCase("A1")) {
            boolean valido = this.baraja.validarCuarteto(this.jugador1, Integer.parseInt(data.substring(2)));
            if (valido == true) {
                for (int i = 0; i < this.jugador1.size(); i++) {
                    if (this.jugador1.get(i).getNumero() == Integer.parseInt(data.substring(2))) {
                        this.jugador1.remove(i);
                        i--;
                    }
                }
                socket.send("A8" + data.substring(2));
                this.jbRealizar.setEnabled(false);
                this.jrBajarse.setEnabled(false);
                this.jrPedir.setEnabled(false);
                this.jcNumero.setEnabled(false);
            } else {

                socket.send("A9");
                this.jbRealizar.setEnabled(true);
                this.jrBajarse.setEnabled(true);
                this.jrPedir.setEnabled(true);
                this.jcNumero.setEnabled(true);
            }

        }


}//GEN-LAST:event_jbRepartirActionPerformed

    private void jbAbandonarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbAbandonarActionPerformed
        // TODO add your handling code here:
        this.dispose();
        this.gc.setVisible(true);

        socket.send("a3");

        try {
            this.ij.dispose();
        } catch (Exception e) {
        }

    }//GEN-LAST:event_jbAbandonarActionPerformed

    private void jlSiguienteMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jlSiguienteMouseClicked


        // TODO add your handling code here:
        if (actual == (this.anfitrion.size() - 1)) {
            actual = 0;
            //this.jtCarta.setText("" + this.anfitrion.get(actual).getNumero() + this.anfitrion.get(actual).getLetra());
            ImageIcon imagenFondoR = new ImageIcon();
            imagenFondoR = new ImageIcon(getClass().getResource(this.anfitrion.get(actual).getURL()));
            this.CartaMuestra.setIcon(imagenFondoR);

        } else {
            actual++;
            //this.jtCarta.setText("" + this.anfitrion.get(actual).getNumero() + this.anfitrion.get(actual).getLetra());
            ImageIcon imagenFondoR = new ImageIcon();
            imagenFondoR = new ImageIcon(getClass().getResource(this.anfitrion.get(actual).getURL()));
            this.CartaMuestra.setIcon(imagenFondoR);
        }






    }//GEN-LAST:event_jlSiguienteMouseClicked

    private void jbConsultarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbConsultarActionPerformed
        // TODO add your handling code here:
        ArrayList<String> jugadores = new ArrayList<String>();
        ArrayList<String> puntajes = new ArrayList<String>();
        jugadores.add(this.jlJugador.getText());
        jugadores.add("Anfitrion");

        puntajes.add("" + this.puntosJugador1);
        puntajes.add("" + this.puntosAlfitrion);

        ij = new InformeJuego(jugadores, puntajes, empates);
        ij.setVisible(true);
    }//GEN-LAST:event_jbConsultarActionPerformed

    private void jbRealizarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbRealizarActionPerformed
        // TODO add your handling code here:
        if ((this.conCuartetosA == 4) && (this.conCuartetosJ == 4)) {
            if (this.conCuartetosA == this.conCuartetosJ) {
                if (this.puntosAlfitrion == this.puntosJugador1) {
                    JOptionPane.showMessageDialog(null, "EMPATE", "INFORMACION", JOptionPane.INFORMATION_MESSAGE);
                    socket.send("A0");
                    this.dispose();
                    this.gc.setVisible(true);
                } else if (this.puntosAlfitrion > this.puntosJugador1) {
                    JOptionPane.showMessageDialog(null, "GANASTE!", "INFORMACION", JOptionPane.INFORMATION_MESSAGE);
                    socket.send("A1");
                    this.dispose();
                    this.gc.setVisible(true);
                } else {
                    JOptionPane.showMessageDialog(null, "PERDISTE!", "INFORMACION", JOptionPane.INFORMATION_MESSAGE);
                    socket.send("A2");
                    this.dispose();
                    this.gc.setVisible(true);
                }
            }
        }
        if ((this.conCuartetosA > 4) || (this.conCuartetosJ > 4)) {

            if (this.conCuartetosA > this.conCuartetosJ) {
                JOptionPane.showMessageDialog(null, "GANASTE!", "INFORMACION", JOptionPane.INFORMATION_MESSAGE);
                socket.send("A1");
                this.dispose();
                this.gc.setVisible(true);
            } else {
                JOptionPane.showMessageDialog(null, "PERDISTE!", "INFORMACION", JOptionPane.INFORMATION_MESSAGE);
                socket.send("A2");
                this.dispose();
                this.gc.setVisible(true);
            }
        }


        boolean valido = false;
        if (this.jrBajarse.isSelected() == true) {
            if (this.jcNumero.getSelectedIndex() == 0) {
                JOptionPane.showMessageDialog(null, "Elija el numero del cuarteto", "INFORMACION", JOptionPane.INFORMATION_MESSAGE);
            } else {
                valido = baraja.validarCuarteto(this.anfitrion, this.jcNumero.getSelectedIndex());
                if (valido == true) {
                    //this.jcNumero.removeItem(""+this.jcNumero.getSelectedIndex());
                    for (int i = 0; i < this.anfitrion.size(); i++) {
                        if (this.anfitrion.get(i).getNumero() == this.jcNumero.getSelectedIndex()) {
                            this.anfitrion.remove(i);
                            i--;
                        }
                    }
                    //this.jtTablero.setText(this.jcNumero.getSelectedIndex()+"A");
                    socket.send("8" + this.jcNumero.getSelectedIndex());
                    JOptionPane.showMessageDialog(null, "Nuevo Cuarteto", "INFORMACION", JOptionPane.INFORMATION_MESSAGE);
                    this.puntosAlfitrion += 4;
                    this.jlPuntos.setText("" + this.puntosAlfitrion);
                    this.conCuartetosA++;

                } else {
                    JOptionPane.showMessageDialog(null, "No hay cuarteto", "INFORMACION", JOptionPane.INFORMATION_MESSAGE);
                    socket.send("9");
                    this.jbRealizar.setEnabled(false);
                    this.jcNumero.setEnabled(false);
                    this.jrBajarse.setEnabled(false);
                    this.jrPedir.setEnabled(false);
                }


            }

        } else if (this.jrPedir.isSelected() == true) {
            if (this.jcNumero.getSelectedIndex() == 0) {
                JOptionPane.showMessageDialog(null, "Elija el numero de la carta a solicitar", "INFORMACION", JOptionPane.INFORMATION_MESSAGE);
            } else {
                Carta c = this.baraja.jugadaModalidad1(this.jcNumero.getSelectedIndex(), this.jugador1);

                if (c != null) {
                    JOptionPane.showMessageDialog(null, "Nueva Carta", "INFORMACION", JOptionPane.INFORMATION_MESSAGE);
                    this.jbRealizar.setEnabled(true);
                    this.anfitrion.add(c);
                    socket.send("A5");
                } else {

                    JOptionPane.showMessageDialog(null, "No hay cartas con ese numero", "INFORMACION", JOptionPane.INFORMATION_MESSAGE);
                    this.jbRealizar.setEnabled(false);
                    socket.send("A4");
                }


            }

        }


    }//GEN-LAST:event_jbRealizarActionPerformed

    private void jrPedirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jrPedirActionPerformed
        // TODO add your handling code here:
        this.jrBajarse.setSelected(false);
    }//GEN-LAST:event_jrPedirActionPerformed

    private void jrBajarseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jrBajarseActionPerformed
        // TODO add your handling code here:

        this.jrPedir.setSelected(false);
    }//GEN-LAST:event_jrBajarseActionPerformed

    private void jlAnteriorMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jlAnteriorMouseClicked
        // TODO add your handling code here:

        if (actual == 0) {
            actual = (this.anfitrion.size() - 1);
            //this.jtCarta.setText("" + this.anfitrion.get(actual).getNumero() + this.anfitrion.get(actual).getLetra());
            ImageIcon imagenFondoR = new ImageIcon();
            imagenFondoR = new ImageIcon(getClass().getResource(this.anfitrion.get(actual).getURL()));
            this.CartaMuestra.setIcon(imagenFondoR);
        } else {
            actual--;
            //this.jtCarta.setText("" + this.anfitrion.get(actual).getNumero() + this.anfitrion.get(actual).getLetra());
            ImageIcon imagenFondoR = new ImageIcon();
            imagenFondoR = new ImageIcon(getClass().getResource(this.anfitrion.get(actual).getURL()));
            this.CartaMuestra.setIcon(imagenFondoR);
        }




    }//GEN-LAST:event_jlAnteriorMouseClicked

    /**
     * @param args the command line arguments
     *//*
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new TableroM2().setVisible(true);
            }
        });
    }*/
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel CartaMuestra;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JButton jbAbandonar;
    private javax.swing.JButton jbConsultar;
    private javax.swing.JButton jbRealizar;
    private javax.swing.JButton jbRepartir;
    private javax.swing.JComboBox jcNumero;
    private javax.swing.JLabel jlAnterior;
    private javax.swing.JLabel jlJugador;
    private javax.swing.JLabel jlNumero;
    private javax.swing.JLabel jlPuntos;
    private javax.swing.JLabel jlSiguiente;
    private javax.swing.JLabel jlTurnoActual;
    private javax.swing.JLabel jlp;
    private javax.swing.JRadioButton jrBajarse;
    private javax.swing.JRadioButton jrPedir;
    // End of variables declaration//GEN-END:variables
}